/*
 ============================================================================
 Page 	     : 293
 Name        : sum_arr2.c
 Date	     : 20210405
 Author      : Hbue 18060333
 Copyright   : Your copyright notice
 Description : 数组元素之和
 ============================================================================
 */

#include <stdio.h>
#define SIZE 10

int sump(int *start, int *end);

int main(void)
{
	int marbles[SIZE] = { 20, 10, 5, 39, 4, 16, 19, 26, 31, 20 };
	long answer = 0;

	answer = sump(marbles, marbles + SIZE);
	printf("The total number of marbles is %ld.\n", answer);

	return 0;
}

/* 使用指针算法 */
int sump(int *start,int *end)
{
	int total = 0;

	while(start < end)
	{
		total += *start;		// 把数组元素的值加起来
		start++;			// 让指针指向下一个元素
	}

	return total;
}

